package fr.unice.polytech.plim.pedometre;

import java.util.ArrayList;

import android.graphics.Canvas;
import android.graphics.Paint;
import android.graphics.Paint.Style;
import android.graphics.Path;
import android.graphics.Point;

import com.google.android.maps.GeoPoint;
import com.google.android.maps.MapView;
import com.google.android.maps.Overlay;
import com.google.android.maps.Projection;

public class MyOverlay extends Overlay {
	
	private ArrayList<GeoPoint> geoPoints = new ArrayList<GeoPoint>();

	@Override
	public void draw(Canvas canvas, MapView mapView, boolean shadow) {
		Projection projection = mapView.getProjection();		
		Path p = new Path();
		for (int i = 0; i < geoPoints.size(); i++) {
			if (i == geoPoints.size() - 1) {
				break;
			}
			Point from = new Point();
			Point to = new Point();
			projection.toPixels(geoPoints.get(i), from);
			projection.toPixels(geoPoints.get(i + 1), to);
			if (i < 1)
				p.moveTo(from.x, from.y);
			p.lineTo(to.x, to.y);
		}
		Paint mPaint = new Paint();
		mPaint.setStyle(Style.STROKE);
		mPaint.setColor(0xFFFF0000);
		mPaint.setAntiAlias(true);
		canvas.drawPath(p, mPaint);
		super.draw(canvas, mapView, shadow);
	}
	
	public void addPoint(GeoPoint point) {
		geoPoints.add(point);
	}
	
	public void resetGeoPoints() {
		geoPoints.clear();
	}

}
